Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement consistent handling of TransactionCanceled errors. #171

Merged
merged 1 commit into from
Jan 19, 2024

Conversation

aclemons
Copy link
Contributor

Previously, the code handling errors would raise the cause of the
cancellation, for example ConditionalCheckFailed or ThrottlingError, if
it was caused by the first item in the list of items in the transaction.

If the failure was caused by any other item in the list, the caller
would see the TransactionCanceled.

This makes is awkward for calling code to handle errors when interested
in the exact item which caused the failure - it needs two except
blocks for handling essentially the same thing. One for when it is the
first item and another for any other item.

This change removes any special handling and bubbles the
TransactionCanceled error up to the caller. I've added a typed
value for the cancellation reasons. These are documented here:

https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_TransactWriteItems.html#API_TransactWriteItems_Errors

This should allow clients to introspect the errors, if needed, with a
typed object.

Closes #170

@aclemons
Copy link
Contributor Author

If we don't like the typed cancellation reasons, I can revert that back out and
leave that for library consumers to handle themselves.

Previously, the code handling errors would raise the cause of the
Cancellation, for example ConditionalCheckFailed or ThrottlingError, if
it was caused by the first item in the list of items in the transaction.

If the failure was caused by any other item in the list, the caller
would see the TransactionCanceled.

This makes is awkward for calling code to handle errors when interested
in the exact item which caused the failure - it needs two `except`
blocks for handling essentially the same thing. One for when it is the
first item and another for any other item.

This change removes any special handling and bubbles the
TransactionCanceled error up to the caller. I've added a type value for
the cancellation reasons. These are documented here:

https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_TransactWriteItems.html#API_TransactWriteItems_Errors

This should allow clients to introspect the errors, if needed, with a
typed object.

Closes HENNGE#170
Copy link
Contributor

@ojii ojii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you. looks pretty good, just some minor stylistic changes I'd appreciate

src/aiodynamo/errors.py Show resolved Hide resolved
src/aiodynamo/errors.py Show resolved Hide resolved
@ojii ojii merged commit 6b2741e into HENNGE:master Jan 19, 2024
27 checks passed
@aclemons aclemons deleted the gh-170 branch January 21, 2024 09:21
@aclemons
Copy link
Contributor Author

Thanks, I had this on my TODO and let it slip out of focus in the new year. Thanks for tidying up and merging.

@aclemons aclemons removed their assignment Jan 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Awkward API for handling TransactionCanceled from transact_write_items
2 participants